#!/bin/bash
#
# Dumps all entities of the datastore into the given file. 
#

USAGE="Usage: gae_dump local|remote file"

if [ $# -lt 2 ]; then
  echo $USAGE
  exit 1
fi

if [ ${0:0:1} = "/" ]; then
  DIR=`dirname $0`
else
  DIR=`pwd`/`dirname $0`
fi 

echo "Work directory: " $DIR
cd $DIR

# Local dev or remote server
if [ $1 = "local" ]; then
  URL="http://localhost:8888/admin/remote_api"
elif [ $1 = "remote" ]; then
  URL="http://virtual-hockey.appspot.com/admin/remote_api"
else
  echo "The first argument must be either 'local' or 'remote'!"
  echo $USAGE
  exit 2
fi 

bulkloader.py --dump --app_id=virtual-hockey --filename=$2 --url=$URL

# Move all bulkloader-* log files to ../../../target/
if [ -d "../../../target" ]; then
  echo "target directory already exists."
else
  echo "Creating target directory."
  mkdir ../../../target
fi

echo "Copying log files to ../../../target"
mv bulkloader-* ../../../target

